spec and agent refactoring

Judy Ngai 9 years ago
parent
commit
8942f74e77
2 changed files with 8 additions and 18 deletions
  1. 6 16
      app/models/agents/twitter_user_agent.rb
  2. 2 2
      spec/models/agents/twitter_user_agent_spec.rb

+ 6 - 16
app/models/agents/twitter_user_agent.rb

@@ -85,7 +85,7 @@ module Agents
85 85
     end
86 86
 
87 87
     def choose_home_time_line?
88
-      interpolated[:choose_home_time_line] == "true"
88
+      boolify(interpolated[:choose_home_time_line]) == "true"
89 89
     end
90 90
 
91 91
     def include_retweets?
@@ -102,26 +102,16 @@ module Agents
102 102
       opts.merge! :since_id => since_id unless since_id.nil?
103 103
 
104 104
       if choose_home_time_line?
105
-
106 105
         tweets = twitter.home_timeline(opts)
107
-
108
-        tweets.each do |tweet|
109
-          if tweet.created_at >= starting_at
110
-            memory['since_id'] = tweet.id if !memory['since_id'] || (tweet.id > memory['since_id'])
111
-
112
-            create_event :payload => tweet.attrs
113
-          end
114
-        end
115
-
116 106
       else
117 107
         tweets = twitter.user_timeline(interpolated['username'], opts)
108
+      end
118 109
 
119
-        tweets.each do |tweet|
120
-          if tweet.created_at >= starting_at
121
-            memory['since_id'] = tweet.id if !memory['since_id'] || (tweet.id > memory['since_id'])
110
+      tweets.each do |tweet|
111
+        if tweet.created_at >= starting_at
112
+          memory['since_id'] = tweet.id if !memory['since_id'] || (tweet.id > memory['since_id'])
122 113
 
123
-            create_event :payload => tweet.attrs
124
-          end
114
+          create_event :payload => tweet.attrs
125 115
         end
126 116
       end
127 117
     end

+ 2 - 2
spec/models/agents/twitter_user_agent_spec.rb

@@ -45,7 +45,6 @@ describe Agents::TwitterUserAgent do
45 45
 
46 46
   describe "#check that if choose time line is false then username is required" do
47 47
     before do
48
-      #stub_request(:any, '/tectonic/').to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
49 48
       stub_request(:any, "https://api.twitter.com/1.1/statuses/user_timeline.json?contributor_details=true&count=200&exclude_replies=false&include_entities=true&include_rts=true").to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
50 49
     end
51 50
 
@@ -56,7 +55,8 @@ describe Agents::TwitterUserAgent do
56 55
       checker = Agents::TwitterUserAgent.new(:name => "tectonic", :options => opts)
57 56
       checker.service = services(:generic)
58 57
       checker.user = users(:bob)
59
-      expect(checker.save).to eq (checker.errors.messages[:base] == "username is required" )
58
+      expect(checker.save).to eq false
59
+      expect(checker.errors.full_messages.first).to eq("username is required")
60 60
     end
61 61
   end
62 62
 end